package com.atlige.gzmall.order.web;

import com.alipay.api.AlipayApiException;
import com.atlige.gzmall.order.config.AlipayTemplate;
import com.atlige.gzmall.order.service.OrderService;
import com.atlige.gzmall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: Jeremy lI
 * @description:
 * @date: created in 2021/7/11 21:43
 */
@Controller
public class PayWebController {
    @Autowired
    AlipayTemplate alipayTemplate;
    @Autowired
    OrderService orderService;

    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {

        PayVo vo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(vo);
        System.out.println(vo);
        return pay;
    }
}
